package com.example.demo.controller;


import com.example.demo.service.OrderInfoService;
import com.example.demo.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chen huilong
 * @since 2022-10-04
 */
@Api(tags = "订单信息管理")
@RestController
@RequestMapping("/demo/order-info")
public class OrderInfoController {

    @Resource
    private OrderInfoService orderInfoService;

    @PostMapping("/submitOrder")
    @ApiOperation("提交订单")
    public Response submitOrder(@RequestHeader("access_token") String access_token, HttpServletRequest request,
                                @RequestBody Map<String, Object> input) {
        Map<String, Object> res = orderInfoService.submitOrder(access_token, request, (String) input.get("buildingId"));
        return Response.success().data(res);
    }

    @PostMapping("/redis/submitOrder")
    @ApiOperation("提交订单")
    public Response submitOrderWithRedis(@RequestHeader("access_token") String access_token, HttpServletRequest request,
                                @RequestBody Map<String, Object> input) {
        Map<String, Object> res = orderInfoService.submitOrderWithRedis(access_token, request, (String) input.get("buildingId"));
        return Response.success().data(res);
    }


    @PostMapping("/getAllOrder")
    @ApiOperation("查询订单列表")
    public Response getAllOrder(@RequestHeader("token") String token) {
        orderInfoService.getAllOrder(token);
        return Response.success();
    }


    @PostMapping("/getOrderResult")
    @ApiOperation("查询订单结果")
    public Response getOrderResult(@RequestHeader("token") String token, @RequestBody String orderId) {
        orderInfoService.getOrderResult(token, orderId);
        return Response.success();
    }


}

